@echo off

set steamcmd=C:\steamcmd\steamcmd.exe
set appid_client=602960
set install_dir_server=C:\Game\Barotrauma\Source
set install_mods_path=C:\Users\Administrator\AppData\Local\Daedalic Entertainment GmbH\Barotrauma\WorkshopMods\Installed

set /p modlistfn=Please input *.modlist file for reading module list:
set modlistfile=.\.store\%modlistfn%.modlist
if not exist "%modlistfile%" (
    echo Not found %modlistfile%!
    goto :eof
)

setlocal EnableDelayedExpansion
set /a len=0
for /f %%i in ('type "%modlistfile%"') do (
    call :updateModule %%i
)
for /l %%i in (1,1,!len!) do (
   set published_file_id=!mods[%%i]!
   set workshop_download_items=!workshop_download_items! +workshop_download_item %appid_client% !published_file_id!
)
%steamcmd% +force_install_dir "%install_dir_server%" +login anonymous !workshop_download_items! +quit
for /l %%i in (1,1,!len!) do (
   set published_file_id=!mods[%%i]!
   set dest=%install_mods_path%\!published_file_id!
   if exist "!dest!" (
      rmdir /s /q "!dest!"
   )
   set src=%install_dir_server%\steamapps\workshop\content\%appid_client%\!published_file_id!
   xcopy /i /e /y "!src!" "!dest!"
)
endlocal
goto :eof

:updateModule
set /a len=!len!+1
set mods[!len!]=%~1
exit /b
